//
// Created by EDZ on 2022/1/26.
//

#ifndef INC_2022_1_TREE_H
#define INC_2022_1_TREE_H

#include "../head/common.h"

__unused TreeNode
*

init() {
    TreeNode * root = new TreeNode;
    root->val = 1;
    stack<TreeNode *> s;
    s.push(root);
    int i = 1;
    while (i < 6) {
        TreeNode * node = s.top();
        s.pop();
        if (node != NULL) {
            cout << node->val << " ";
        }
        TreeNode * left = new TreeNode;
        left->val = ++i;
        node->left = left;
        TreeNode * right = new TreeNode;
        right->val = ++i;
        node->right = right;
        s.push(node->right);
        s.push(node->left);
    }
    return root;
}

void stackTrace(TreeNode * root) {
    stack<TreeNode *> s;
    s.push(root);
    while (!s.empty()) {
        TreeNode * node = s.top();
        s.pop();
        if (node != NULL) {
            cout << node->val << " ";
        }
        if (node->right != NULL)
            s.push(node->right);
        if (node->left != NULL)
            s.push(node->left);
    }

}

void print(TreeNode * root) {
    queue<TreeNode *> q;
    q.push(root);
    while (!q.empty()) {
        TreeNode * node = q.front();
        q.pop();
        cout << node->val << " ";
        if (node->left != NULL)
            q.push(node->left);
        if (node->right != NULL)
            q.push(node->right);
    }
}
//二叉树剪枝、回溯
#endif //INC_2022_1_TREE_H
